#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

#include <sys/time.h>
#include <errno.h>

int main(int argc,char **argv)
{
    int i = 0;
    struct timeval tv1,tv2;
    struct timespec tp1,tp2;

    gettimeofday(&tv1,NULL);
    //usleep(10);
    /*
     * On PC ,this cost 5 us
     * On Hi3516cv500, this cost 12 us
     * On Hi3516ev100, this cost 17 us
     */
    while(i<1000) i += 1;
    gettimeofday(&tv2,NULL);
    printf("gettimeofday resolution = %ld us\n",tv2.tv_usec - tv1.tv_usec);

    clock_gettime(CLOCK_MONOTONIC,&tp1);
    //usleep(10);
    i = 0;
    while(i<1000) i += 1;
    clock_gettime(CLOCK_MONOTONIC,&tp2);
    printf("clock_gettime resolution = %ld us\n",(tp2.tv_nsec - tp1.tv_nsec)/1000);
    return 0;
}
